﻿using Microsoft.Graphics.Canvas;
using Microsoft.Graphics.Canvas.Effects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace 纸片人.win2dEffectControl.DataClass
{
    public class Transform2DEffectData : EffectTwoSourceData
    {
        #region 属性
        private float _sharpness;
        EffectBorderMode _effectBorderMode = EffectBorderMode.Soft;
        CanvasImageInterpolation _interpolationMode = CanvasImageInterpolation.NearestNeighbor;
        Matrix3x2 _transformMatrix = Matrix3x2.Identity;

        public float Sharpness
        {
            get => _sharpness;
            set
            {
                _sharpness = value;

                if (value > 2.0)
                {
                    _sharpness = 2.0f;
                }
                OnPropertyChanged();
                SetIsChanges();
            }
        }
        public EffectBorderMode EffectBorderMode
        {
            get => _effectBorderMode; set { _effectBorderMode = value; OnPropertyChanged(); SetIsChanges(); }
        }
        public CanvasImageInterpolation InterpolationMode
        {
            get => _interpolationMode; set { _interpolationMode = value; OnPropertyChanged(); SetIsChanges(); }
        }
        public Matrix3x2 TransformMatrix
        {
            get => _transformMatrix; set { _transformMatrix = value; OnPropertyChanged(); SetIsChanges(); }
        }
        #endregion

        public override ICanvasImage GetEffect(CanvasDevice device, bool compression)
        {
            if (InputEffectData == null)
            {
                Size = new Windows.Foundation.Size(0, 0);
                return null;

            }

            var source = GetSourceEffect(device, compression);
            if (source == null)
            {
                Size = new Windows.Foundation.Size(0, 0);
                return null;

            }

            var te = new Transform2DEffect();

            Transform2DEffect effect = new Transform2DEffect()
            {
                BorderMode = EffectBorderMode,
                InterpolationMode = InterpolationMode,
                Sharpness = Sharpness,
                TransformMatrix = TransformMatrix,
                Source = source,

            };

         

            return effect;
        }
    }
}
